package com.java2020.online_mall.service;

import com.java2020.online_mall.dao.OrderDao;
import com.java2020.online_mall.dao.OrderDaoImpl;
import com.java2020.online_mall.model.Order;
import com.java2020.online_mall.model.OrderRequestParam;
import com.java2020.online_mall.model.OrderResponse;
import com.java2020.online_mall.model.User;

import java.util.List;

/**
 * @PackgeName: com.java2020.online_mall.service
 * @Author: MNHK
 * Date: 2020/5/4 9:05
 * @Version:1.8
 */

public class OrderServiceImpl implements OrderService{

    private OrderDao orderDao = new OrderDaoImpl();

    @Override
    public OrderResponse ordersByPage(OrderRequestParam param) {
        //多条件查询
        Integer total = orderDao.getTotal(param);
        //根据条件查询出具体的订单数据
        List<Order> orderList = orderDao.ordersByPage(param);
        for (Order order : orderList) {
            User user = new User(order.getNickname(),order.getName(),order.getAddress(),order.getPhone());
            order.setUser(user);
            //取出stateId，然后根据不同，设置不同的state的值
        }
        OrderResponse orderResponse = new OrderResponse();
        orderResponse.setTotal(total);
        orderResponse.setOrders(orderList);
        return orderResponse;
    }
}
